home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / c-runtime / dispatch / RCS / hash-inline.h,v < prev    next >
Encoding:
Text File  |  1992-01-03  |  7.3 KB  |  318 lines

  1. head    1.6;
  2. access;
  3. symbols;
  4. locks
  5.     dennisg:1.6; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.6
  10. date    92.01.03.02.55.03;    author dennisg;    state Exp;
  11. branches;
  12. next    1.5;
  13.  
  14. 1.5
  15. date    91.12.10.12.05.28;    author dennisg;    state Exp;
  16. branches;
  17. next    1.4;
  18.  
  19. 1.4
  20. date    91.12.03.02.01.23;    author dennisg;    state Exp;
  21. branches;
  22. next    1.3;
  23.  
  24. 1.3
  25. date    91.11.24.14.48.02;    author dennisg;    state Exp;
  26. branches;
  27. next    1.2;
  28.  
  29. 1.2
  30. date    91.11.24.01.20.02;    author dennisg;    state Exp;
  31. branches;
  32. next    1.1;
  33.  
  34. 1.1
  35. date    91.11.23.22.20.42;    author dennisg;    state Exp;
  36. branches;
  37. next    ;
  38.  
  39.  
  40. desc
  41. @this file holds some functions from hash.c that have been
  42. converted to inlines.
  43. @
  44.  
  45.  
  46. 1.6
  47. log
  48. @modified to handle new initialization scheme.
  49. fixed code structure.
  50. @
  51. text
  52. @/* -*-c-*-
  53.  * This file contains certain functions of
  54.  *  the hashing algorithm that are inline.  
  55.  * These functions are used in critical regions
  56.  *  of the run-time where inlining can improve
  57.  *  performance.
  58.  *
  59.  * Copyright (C) 1991 Threaded Technologies Inc.
  60.  * 
  61.  * This program is free software; you can redistribute it and/or modify
  62.  * it under the terms of the GNU General Public License as published
  63.  * by the Free Software Foundation; either version 1, or any later version.
  64.  * 
  65.  * This program is distributed in the hope that it will be useful,
  66.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  67.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  68.  * General Public License for more details.
  69.  * 
  70.  * You should receive a copy of the GNU General Public License 
  71.  * along with this program; if not, write to the Free Software
  72.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  73.  * 
  74.   $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash-inline.h,v 1.5 1991/12/10 12:05:28 dennisg Exp dennisg $
  75.   $Author: dennisg $
  76.   $Date: 1991/12/10 12:05:28 $
  77.   $Log: hash-inline.h,v $
  78.  * Revision 1.5  1991/12/10  12:05:28  dennisg
  79.  * Cleaned up file format for a distribution.
  80.  *
  81.  * Revision 1.4  1991/12/03  02:01:23  dennisg
  82.  * fixed assert macro.
  83.  * added memory allocation adjustment macro for hash size allocation.
  84.  *
  85.  * Revision 1.3  1991/11/24  14:48:02  dennisg
  86.  * modified hash_value_for_key () to remove two variables.
  87.  * "indx" was initialized with a value from a function then used only once.
  88.  * the information used in "found" can be terermined from "retVal".
  89.  *
  90.  * Revision 1.2  1991/11/24  01:20:02  dennisg
  91.  * changed shorts back to ints.
  92.  * the efficiency gained didn't out weight the grossness of the code.
  93.  *
  94.  * Revision 1.1  1991/11/23  22:20:42  dennisg
  95.  * Initial revision
  96.  *
  97. */
  98.  
  99. #ifndef _hash_inline_INCLUDE_GNU
  100. #define _hash_inline_INCLUDE_GNU
  101.  
  102.                                                 /* If someone is using a c++
  103.                                                   compiler then adjust the 
  104.                                                   types in the file back 
  105.                                                   to C. */
  106. #ifdef __cplusplus
  107. extern "C" {
  108. #endif
  109.  
  110. #include  <assert.h>
  111. #include  <hash.h>
  112. #include  <ObjC.h>
  113. #include  <stddef.h>
  114. #include  <stdlib.h>
  115. #include  <sys/types.h>
  116.  
  117.  
  118.                                                 /* Function that is private
  119.                                                   to the hashing code.  It
  120.                                                   returns a hash table index 
  121.                                                   calculated from a key. */
  122. static inline u_int hashIndex(Cache_t theCache, void* aKey) {
  123.  
  124.  
  125.   assert(sizeof (u_int) == sizeof (aKey));
  126.  
  127.   return ((u_int)aKey) % theCache->sizeOfHash;
  128. }
  129.  
  130.  
  131.                                                 /* Given key, return its 
  132.                                                   value.  Return NULL if the
  133.                                                   key/value pair isn't in
  134.                                                   the hash. */
  135. static inline void* hash_value_for_key (Cache_t theCache, void* aKey) {
  136.  
  137.   CacheNode_t aCacheNode = 
  138.                  (*theCache->theNodeTable)[ hashIndex(theCache, aKey) ];
  139.   void*       retVal = NULL;
  140.   
  141.  
  142.   if (aCacheNode)
  143.     do {
  144.       if (aCacheNode->theKey == aKey)
  145.         retVal = aCacheNode->theValue;
  146.       else
  147.         aCacheNode = aCacheNode->nextNode;
  148.     } while (!retVal && aCacheNode);
  149.   
  150.   return retVal;
  151. }
  152.  
  153.  
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157.  
  158. #endif
  159. @
  160.  
  161.  
  162. 1.5
  163. log
  164. @Cleaned up file format for a distribution.
  165. @
  166. text
  167. @d23 1
  168. a23 1
  169.   $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash-inline.h,v 1.4 1991/12/03 02:01:23 dennisg Exp dennisg $
  170. d25 1
  171. a25 1
  172.   $Date: 1991/12/03 02:01:23 $
  173. d27 3
  174. a60 1
  175. #include  <libc.h>
  176. d62 2
  177. @
  178.  
  179.  
  180. 1.4
  181. log
  182. @fixed assert macro.
  183. added memory allocation adjustment macro for hash size allocation.
  184. @
  185. text
  186. @d3 1
  187. a3 1
  188.  *    the hashing algorithm that are inline.  
  189. d5 2
  190. a6 2
  191.  *    of the run-time where inlining can improve
  192.  *    performance.
  193. d23 1
  194. a23 1
  195.   $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash-inline.h,v 1.3 1991/11/24 14:48:02 dennisg Exp dennisg $
  196. d25 1
  197. a25 1
  198.   $Date: 1991/11/24 14:48:02 $
  199. d27 4
  200. d56 4
  201. a59 4
  202. #include    <assert.h>
  203. #include    <hash.h>
  204. #include    <libc.h>
  205. #include    <ObjC.h>
  206. d63 4
  207. a66 4
  208.                                                                                                 /* Function that is private
  209.                                                                                                     to the hashing code.  It
  210.                                                                                                     returns a hash table index 
  211.                                                                                                     calculated from a key. */
  212. d70 1
  213. a70 1
  214.     assert(sizeof (u_int) == sizeof (aKey));
  215. d72 1
  216. a72 1
  217.     return ((u_int)aKey) % theCache->sizeOfHash;
  218. d83 1
  219. a83 1
  220.                                  (*theCache->theNodeTable)[ hashIndex(theCache, aKey) ];
  221. @
  222.  
  223.  
  224. 1.3
  225. log
  226. @modified hash_value_for_key() to remove two variables.
  227. "indx" was initialized with a value from a function then used only once.
  228. the information used in "found" can be terermined from "retVal".
  229. @
  230. text
  231. @d23 1
  232. a23 1
  233.   $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash-inline.h,v 1.2 1991/11/24 01:20:02 dennisg Exp dennisg $
  234. d25 1
  235. a25 1
  236.   $Date: 1991/11/24 01:20:02 $
  237. d27 5
  238. d63 1
  239. a63 1
  240. static inline u_int hashIndex (Cache_t theCache, void* aKey) {
  241. d66 3
  242. a68 3
  243.     assert (sizeof (u_int) == sizeof (aKey));
  244.     
  245.     return (u_int)aKey % theCache->sizeOfHash ;
  246. d79 1
  247. a79 1
  248.                                  (*theCache->theNodeTable)[ hashIndex (theCache, aKey) ];
  249. @
  250.  
  251.  
  252. 1.2
  253. log
  254. @changed shorts back to ints.
  255. the efficiency gained didn't out weight the grossness of the code.
  256. @
  257. text
  258. @d23 1
  259. a23 1
  260.   $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash-inline.h,v 1.1 1991/11/23 22:20:42 dennisg Exp dennisg $
  261. d25 1
  262. a25 1
  263.   $Date: 1991/11/23 22:20:42 $
  264. d27 4
  265. d58 1
  266. a58 1
  267. static inline u_int hashIndex( Cache_t theCache, void* aKey ) {
  268. d71 1
  269. a71 1
  270. static inline void* hash_value_for_key( Cache_t theCache, void* aKey ) {
  271. d73 2
  272. a74 2
  273.   u_int       indx = hashIndex( theCache, aKey );
  274.   CacheNode_t aCacheNode = ( *theCache->theNodeTable )[ indx ];
  275. d78 1
  276. a78 3
  277.   if( aCacheNode ) {
  278.     BOOL  found = NO;
  279.   
  280. d80 2
  281. a81 2
  282.       if( aCacheNode->theKey == aKey )
  283.         retVal = aCacheNode->theValue, found = YES;
  284. d84 1
  285. a84 2
  286.     } while( !found && aCacheNode );
  287.   }
  288. @
  289.  
  290.  
  291. 1.1
  292. log
  293. @Initial revision
  294. @
  295. text
  296. @d23 1
  297. a23 1
  298.   $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.6 1991/11/21 22:27:06 dennisg Exp dennisg $
  299. d25 5
  300. a29 2
  301.   $Date: 1991/11/21 22:27:06 $
  302.   $Log: hash.c,v $
  303. d54 1
  304. a54 1
  305. static inline u_short hashIndex( Cache_t theCache, void* aKey ) {
  306. d57 1
  307. a57 1
  308.     assert ((2*sizeof (u_short)) == sizeof (aKey));
  309. d59 1
  310. a59 3
  311.     return ((*((u_short(*)[])&aKey))[0] ^ 
  312.                         (*((u_short(*)[])&aKey))[1]) % 
  313.                         (u_short)theCache->sizeOfHash ;
  314. d69 1
  315. a69 1
  316.   u_short     indx = hashIndex( theCache, aKey );
  317. @
  318.